package com.meirimoney.app;

import net.youmi.android.AdManager;
import net.youmi.android.offers.OffersManager;
import cn.domob.offer.wall.data.DomobOfferWallErrorInfo;
import cn.domob.offer.wall.data.DomobOfferWallManager;
import cn.domob.offer.wall.data.DomobOfferWallManager.AddWallListener;

import com.dlnetwork.Dianle;
import com.imopan.mpwall.MopanWallManager;
import com.juzi.main.AppConnect;
import com.meirimoney.app.control.MenuBar;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

public class AdvertisingPanel extends BaseActivity implements OnClickListener {
	/**
	 ********* 广告墙配置开始*********
	 * 
	 */

	/**
	 * 初始化有米广告
	 */
	private void initializeYoumi() {
		// 初始化应用发布ID和密钥，以及设置测试模式
		AdManager.getInstance(this).init("e6f8078b0e844c23",
				"2547711bbd378bea", false);// false

		// 请务必调用以下代码，告诉SDK应用启动，可以让SDK进行一些初始化操作。该接口务必在SDK的初始化接口之后调用。
		OffersManager.getInstance(this).onAppLaunch();

		// 调用以下接口关闭有米广告SDK相关的log
		AdManager.getInstance(this).setEnableDebugLog(false);
		OffersManager.getInstance(this).setCustomUserId(
				this.getUser().getUserId());
	}

	/**
	 * 初始化桔子广告
	 */
	private void initializeJuzi() {
		AppConnect.getInstance(this);
	}

	/**
	 * 万普世纪广告配置
	 */
	private void initializeWaps() {
		cn.waps.AppConnect.getInstance("6fd353db448d53a8c3032664d7684848",
				"gfan", this); // 设置WAPS_ID和WAPS_PID
		cn.waps.AppConnect.getInstance(this).setAdViewClassName(
				"com.meirimoney.app.WapsWebView");
		/**
		 * cn.waps.AppConnect.getInstance(this);
		 **/
	}

	/**
	 * 初始化点乐
	 */
	private void initializeDianle() {
		Dianle.initDianleContext(this, "727f0dceb567c4c7dda23002cdb380d9");
		Dianle.setCustomActivity(this.getPackageName() + ".DianleWall");
		Dianle.setCustomService(this.getPackageName() + ".DianleWallService");
		Dianle.setCurrentUserID(this.getUser().getUserId());
	}

	/**
	 * 初始化多盟广告
	 * 
	 * @return 多盟广告的实例
	 */
	private DomobOfferWallManager initializeDomob() {
		return new DomobOfferWallManager(this, "96ZJ0UEQze23HwTA7v", this
				.getUser().getUserId());
	}
	
	/**
	 *初始化磨盘广告
	 */
	
	private void initializeMopanWall()
	{
		 // 设置磨盘SDK帐号
		MopanWallManager.getInstance(this).startMopanWall("12286", "xb00ez4bhajcq8kh");
		MopanWallManager.getInstance(this).setCustomParam(this.getUser().getUserId());
		
	}

	/**
	 * 加载广告
	 */
	public void loadAdvertising() {
		this.initializeYoumi();
		//this.initializeJuzi();
		this.initializeDianle();
		this.initializeWaps();
		this.initializeMopanWall();
	}

	/**
	 * 卸载广告
	 */
	public void unloadAdvertising() {
		/**
		 * 有米的广告卸载
		 */
		OffersManager.getInstance(this).onAppExit();

		/**
		 * 桔子广告卸载
		 */
		AppConnect.getInstance(this).finalize();

		/**
		 * 万普世纪广告卸载
		 */
		cn.waps.AppConnect.getInstance(this).close();
	}

	/**
	 ********** 广告墙配置结束**********
	 */

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.loadAdvertising();
		this.initializeUI();
		this.setTitle("任务列表");
	}

	/***
	 * 初始化当前界面的UI
	 */
	private void initializeUI() {
		this.setContentView(R.layout.mrm_advertising_list);
		if (null == this.navigation) {
			this.navigation = (MenuBar) this.findViewById(R.id.head);
		}
		if (null == this.youmiNavigation) {
			this.youmiNavigation = (TextView) this.findViewById(R.id.goYoumi);
			this.youmiNavigation.setOnClickListener(this);
		}
		if (null == this.dianleNavigation) {
			this.dianleNavigation = (TextView) this.findViewById(R.id.goDianLe);
			this.dianleNavigation.setOnClickListener(this);
		}
		if (null == this.domobNavigation) {
			this.domobNavigation = (TextView) this.findViewById(R.id.goDomob);
			this.domobNavigation.setOnClickListener(this);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.goYoumi: {
			OffersManager.getInstance(this).showOffersWall();
			break;
		}
		case R.id.goDianLe: {
			Dianle.showOffers();
			break;
		}
		case R.id.goDomob: {
			/*
			if (null == this.domobOfferWallManager) {
				this.domobOfferWallManager=this.initializeDomob();
			}
			this.domobOfferWallManager.loadOfferWall();
			*/
			MopanWallManager.getInstance(this).showAppWall();
		}
		default: {
			break;
		}
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		this.unloadAdvertising();
	}

	/**
	 * 有米导航
	 */
	private TextView youmiNavigation;

	/**
	 * 点乐导航
	 */
	private TextView dianleNavigation;

	/**
	 * 多盟广告导航
	 */
	private TextView domobNavigation;

	/**
	 * 多盟广告实例
	 */
	private DomobOfferWallManager domobOfferWallManager;

}
